package com.campus_information_portal.dao;


import com.campus_information_portal.entity.PartyMemberPartyStudent;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author 20155883 万珊
 * @description 党支部成员信息的动态查询
 * @project_name PartyMemberSqlProvider
 * @package com.campus_information_portal.dao
 * @create 2018-05-12 16:40
 **/
public class PartyMemberSqlProvider {
    public String queryPartyMemberByConditions(PartyMemberPartyStudent partyMemberPartyStudent) {
        StringBuilder sql = new StringBuilder("select p.*,pm.*,s.* from party_member pm,party p,student s where p.party_info_id=pm.party_info_id and pm.stu_info_id=s.stu_info_id and pm.te_info_id=0 and 1=1");
        if ((partyMemberPartyStudent.getPartyName()!=null)&&(partyMemberPartyStudent.getPartyName().length()>0)){
            sql.append(" and p.party_name=#{partyName}");
        }
        if((partyMemberPartyStudent.getPartyMemberType()!=null)&&(partyMemberPartyStudent.getPartyMemberType()!=0)){
            sql.append(" and pm.party_member_type=#{partyMemberType}");
        }
        if ((partyMemberPartyStudent.getStuGrade()!=null)&&(partyMemberPartyStudent.getStuGrade()!=0)){
            sql.append(" and s.stu_grade=#{stuGrade}");
        }
        return sql.toString();
    }


//    public String queryPartyMemberByConditions(final PartyMemberPartyStudent partyMemberPartyStudent) {
//        return new SQL() {{
//            SELECT("p.*");
//            SELECT("pm.*");
//            SELECT("s.*");
//            FROM("party_member pm,party p,student s");
//            if (partyMemberPartyStudent.getPartyName()!=null) {
//                WHERE("p.party_name=#{partyName}");
//            }
//            if(partyMemberPartyStudent.getPartyMemberType()!=null) {
//                WHERE("pm.party_member_type=#{partyMemberType}");
//            }
//            if (partyMemberPartyStudent.getStuGrade()!=null) {
//                WHERE("s.stu_grade=#{stuGrade}");
//            }
//
//        }}.toString();
//    }
}
